<?php


require_once($INCLUDE_PATH . "app/plugins/smarty/Smarty.class.php");

class DyTemplate extends Smarty {

  const PER_CACHE = 2;
  /*
   * Default cache time is 20 minutes
   */
  public function DyTemplate($caching=false, $cacheTime=1200) {
    global $INCLUDE_PATH;

    $this->Smarty();

    $this->template_dir = $INCLUDE_PATH . "templates/";
    $this->compile_dir  = $INCLUDE_PATH . "templates_c/";
    $this->config_dir   = $INCLUDE_PATH . "configs/";
    $this->cache_dir    = $INCLUDE_PATH . "cache/";

    $this->left_delimiter = "<{";
    $this->right_delimiter = "}>";

    //$this->caching = true;
    if ($caching) {
      $this->caching = 2;
    }

    if (!is_null($cacheTime)) {
      $this->cache_lifetime = $cacheTime;
    }
  }

  public function setCaching($c) 
  {
    $this->caching = $c;
  }

  public function setCacheTime($ct)
  {
    $this->cache_lifetime = $ct;
  }

  public function set($name, $val = null) {
    $this->assign($name, $val);
  }

  public function isCached($tplName, $cacheId = NULL) {
    return $this->is_cached($tplName, $cacheId);
  }

  public function registerFunction($tagName, $funcName) {
    $this->register_function($tagName, $funcName);
  }

  public function registerBlock($tagName, $funcName=null) {
    if ($funcName == null) {
      $this->register_block($tagName, "Dy_default_dynamic_block_func", false);
    } else {
      $this->register_block($tagName, $funcName, false);
    }
  }

  public function getOutput($tplName, $cacheId = NULL) {
    return $this->fetch($tplName, $cacheId);
  }

  public function render($tplName, $cacheId = NULL) {
    $this->display($tplName, $cacheId);
  }
 
}

function Dy_default_dynamic_block_func($param, $content, &$smarty) {
  return $content;
}

?>
